<?
require_once("cms/newsletter/om/SubscriberPeer.php");

class PHP_CMS_View_Helper_Recipients {

    public function recipients($form, $operator="NOT IN") {

        $c = new Criteria();

        $c->add(SubscriberPeer::SUBSCRIBER_ID,
            "subscriber_id ". $operator .
            " (SELECT subscriber_id FROM newsletter_subscriber" .
            " WHERE received = 1" .
            " AND newsletter_id = '".mysql_real_escape_string($form->getId())."')",
            Criteria::CUSTOM);


        if($operator == "NOT IN") {
            $c->add(SubscriberPeer::ACTIVE, true);
//            $c->add(NewsletterPeer::TYPE, $form->getTypes(), Criteria::IN);
//            $c->add(NewsletterPeer::COUNTRY_CODE, $form->getCountries(), Criteria::IN);
        }
        
        return SubscriberPeer::doSelect($c);

    }

}
?>